package com.zzxx.controller;

import com.zzxx.entity.Orders;
import com.zzxx.entity.UserCoupon;
import com.zzxx.mapper.UserCouponMapper;
import com.zzxx.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserCouponMapper userCouponMapper;

    @RequestMapping("queryByUserId")
    public List<Orders> findByUserId(@RequestParam String bookerid){
        return orderService.findByUserId(bookerid);
    }

    @RequestMapping("findOrderById")
    public Orders findOrderById(@RequestParam String id){
        return orderService.findOrdersById(id);
    }

    @RequestMapping("updateById")
    public Integer updateById(@RequestParam String id){
        return orderService.updateById(id);
    }

    @RequestMapping(value = "createdOrder",method = RequestMethod.POST)
    public Integer createdOrder(@RequestBody Map<String,Orders> map){
        Orders orders = map.get("orders");//前端
        orderService.createQr(orders);
        if(orders.getCouponid()!=null){
            UserCoupon userCoupon = userCouponMapper.selectByPrimaryKey(orders.getCouponid());
            userCoupon.setStatus(1);
            userCouponMapper.updateByPrimaryKey(userCoupon);
        }

        return orderService.createdOrder(orders);
    }
    @RequestMapping("price")
    public double price(@RequestParam double price,double number ){
        double one =price*number;
        BigDecimal two=new BigDecimal(one);
        double three = two.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
        return  three;
    }
}
